package homework.course.role.state;

import homework.course.Message;
import homework.course.MessageType;
import homework.course.role.Student;

public class PlayingState extends StudentState {

    private boolean invaild = false;

    public PlayingState(Student std) {
        super(std, "手游", "开始玩手游");
    }

    public void forfeit() {
        invaild = true;
        std.notifyObservers(new Message("手机被没收了", MessageType.SYSTEM));
        std.setState(std.getConcentrateState());
    }

    public boolean isForfeited() {
        return invaild;
    }

    @Override
    public String speak() {
        String msg = "推中!推中!猪队友!";
        std.notifyObservers(new Message(msg, MessageType.WORDS));
        return msg;
    }

    @Override
    public void listen(Object obj, String msg) {
        if(Math.round(Math.random()*3) == 0) {
            std.notifyObservers(new Message("游戏输了,很郁闷", MessageType.SYSTEM));
            std.setState(std.getDistractedState());
        } else {
            std.notifyObservers(new Message("不为所动,手指飞快的敲击着手机屏幕", MessageType.SYSTEM));
        }
    }
}
